import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import * as bodyParser from 'body-parser';
import { AppModule } from './app.module';
import { AllExceptionsFilter } from './any-exception.filter';
import { logger } from './middleware/logger.middleware';
import AppConfig from "../config/app.config";


async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  const config = new DocumentBuilder()
    .setTitle('Node服务API')
    .setDescription('Node服务API')
    .setVersion('1.0')
    .addTag('Node Server API')
    .build();
  const document = SwaggerModule.createDocument(app, config);

  SwaggerModule.setup(`${AppConfig.GlobalApiPrefix}/doc`, app, document);
  // the next two lines did the trick
  app.use(bodyParser.json({limit: '50mb'}));
  app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
  app.use(logger);
  // app.useGlobalInterceptors(new TransformInterceptor());
  app.enableCors();
  app.useGlobalFilters(new AllExceptionsFilter());
  app.setGlobalPrefix(AppConfig.GlobalApiPrefix);//设置全局路由前缀
  await app.listen(6889);
}
bootstrap();
